package luj.tool.jnproxyan.proxy.admin.page.connect;

import luj.tool.jnproxyan.proxy.admin.AdminHttpHandler;
import luj.tool.jnproxyan.proxy.admin.AdminHttpMeta;
import luj.tool.jnproxyan.proxy.admin.AdminHttpModule;
import luj.tool.jnproxyan.proxy.admin.util.SocksTeller;
import luj.tool.jnproxyan.proxy.network.socks.actor.root.message.admin.connect.history.ConnectHistoryMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
final class ConnectHistoryPage implements AdminHttpHandler {

  @Component
  class Meta implements AdminHttpMeta {

    @Override
    public AdminHttpModule module() {
      return AdminConnectDir.INSTANCE;
    }

    @Override
    public String path() {
      return "/history";
    }
  }

  /**
   * @see luj.tool.jnproxyan.proxy.network.socks.actor.root.message.admin.connect.history.OnConnectHistory#onHandle
   */
  @Override
  public void onHandle(Context ctx) throws Exception {
    _teller.inject(ctx).tell(ConnectHistoryMsg.class, (b, m) -> b
        .f(m::http).set(ctx)
    );
  }

  @Autowired
  SocksTeller _teller;
}
